<template>
	<view class="home-tab-bar">
		<view
			v-for="(item, index) in formatList"
			:key="index"
			:class="[`item ${index === homeCurrentTabbar ? 'checked' : ''}`]"
			v-if="item.status"
			@click="handleTabActions(item.pagePath, index)"
		>
			<view class="tab-circle-wrap" v-if="push&&index==2">
				<view class="icon-wrap icon-wrap--push">
					<text class="iconfontPT iconadd1 icon-wrap__icon"></text>
				</view>
				<view class="name">发布</view>
			</view>
			<view class="tab-circle-wrap" v-else-if="index == 2">
				<view class="icon-wrap">
					<text :class="[`iconfontPT ${item.iconClassName}`]"></text>
				</view>
				<view class="name">{{ item.name }}</view>
			</view>

			<block v-else>
				<view class="icon-wrap">
					<text :class="[`iconfontPT ${item.iconClassName}`]"></text>
				</view>
				<view class="name">{{ item.name }}</view>
			</block>
		</view>
	</view>
</template>

<script>
import { mapGetters } from 'vuex';

export default {
	props:{
		showstatus: {},
		push:{
			type:Boolean,
			default:false
		}
	},
	data() {
		return {
			list: [
				{
					index: 0,
					pagePath: '/pages/index/index',
					name: '首页',
					iconClassName: 'iconshouye'
				},

				{
					index: 1,
					pagePath: '/pages/new-car',
					name: '新车',
					iconClassName: 'iconcar'
				},
				{
					index: 2,
					pagePath: '/pages/life-circle',
					name: '圈友',
					iconClassName: 'iconquanziguanli'
				},
				{
					index: 3,
					pagePath: '/pages/used-car',
					name: '二手车',
					iconClassName: 'iconCar2'
				},
				{
					index: 4,
					pagePath: '/pages/personal',
					name: '我的',
					iconClassName: 'iconwode1'
				}
			]
		};
	},
	computed: {
		...mapGetters(['homeCurrentTabbar']),
		formatList() {
			let showStatus = this.showstatus ? this.showstatus : uni.getStorageSync('showSataus');

			return this.list.map((item, index) => {
				item.status = index === 2 ? showStatus : 1;

				return item;
			});
		}
	},
	methods: {
		handleTabActions(url, index) {
			if((index===2||index===4) && !uni.getStorageSync('openId')){
				uni.navigateTo({url:'/pages/authorize'})
				return false
			}
			if(this.push&&index === 2){
				 this.$emit('push')
			}else{
				
				if (this.list[index] === this.homeCurrentTabbar) return;
				
				uni.switchTab({
					url
				});
				this.$store.dispatch('home-tab-bar/setCurrentTabbar', index);
			}
		}
	}
};
</script>

<style lang="less">
.home-tab-bar {
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 112;
	display: flex;
	height: 136rpx;
	position: fixed;
	background: white;
	padding-top: 20px;
	padding-bottom: 68rpx;
	box-sizing: border-box;
	box-shadow: 0rpx 0rpx 8rpx 0rpx rgba(0, 0, 0, 0.1);

	.item {
		flex: 1;
		display: flex;
		margin-top: 10rpx;
		text-align: center;
		align-items: center;
		flex-direction: column;
		justify-content: center;
		
		.tab-circle-wrap {
			margin-top: -40rpx;
			
			.icon-wrap {
				padding: 16rpx;
				border-radius: 50%;
				background-color: #fff;
				box-shadow: 0rpx 0rpx 8rpx 0rpx rgba(0, 0, 0, 0.1);
				width: 56rpx;
				height: 56rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
			
			.iconfontPT.iconquanziguanli {
				font-size: 54rpx;
			}
		}

		// &:nth-child(3) {
		// 	.icon-wrap {
		// 		border: 22rpx solid #FF8080;
		// 		border-radius: 50%;
		// 		background-color: #FF8080;
		// 		display: flex;
		// 		align-items: center;
		// 		justify-content: center;
		// 	}

		// 	.iconfontPT.iconquanziguanli {
		// 		color: #fff;
		// 	}
		// }

		&.checked {
			.icon-wrap {
				.iconfontPT {
					color: #e41805;
				}
			}

			.name {
				color: #e41805;
			}
		}

		.name {
			font-size: 26rpx;
			color: #666666;
		}

		.icon-wrap {
			position: relative;
			margin-bottom: 10rpx;

			.iconfontPT {
				color: #bfbfbf;
				font-size: 44rpx;
			}

			.number {
				top: -6rpx;
				color: #fff;
				padding: 8rpx;
				right: -15rpx;
				font-size: 20rpx;
				min-width: 18rpx;
				min-height: 18rpx;
				line-height: 18rpx;
				position: absolute;
				background: #ff5618;
				border-radius: 50rpx;
				border: 3rpx solid #fff;
			}
		}
	}
}
.icon-wrap{
	&--push{
		background-color: #e41805 !important;
	}
	&__icon{
		color: #FFFFFF !important;
	}
}
</style>
